package com.cheng.example.java.version.java8.chap04_methference;

import lombok.Data;

@FunctionalInterface
interface Converter<F, T> {
    T convert(F from);
}

@Data
class Person {
    String firstName;
    String lastName;
    Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
}

public class Test {

   static int flag = 1;

    public int valueOf(String s) {
      return  Integer.valueOf(s);
    }

    interface PersonFactory<P extends Person> {
        P create(String firstName, String lastName);
    }

    public static void main(String[] args) {

        //1、静态方法引用
        Converter<String, Integer> converter =Integer::valueOf;
        //2、普通方法引用
        converter = new Test()::valueOf;
        Integer converted = converter.convert("123");
        System.out.println(converted);    // 123
        //3、构造函数引用
        PersonFactory<Person> personFactory = Person::new;
        Person person = personFactory.create("Peter", "Parker");
        int i=1;
        //4、拉姆达表达式作用域问题,只能是static和final修饰
        converter = (from) -> Integer.valueOf(from + i);

        converter = (from) -> Integer.valueOf(from + i);

    }


}
